<template>
    <div class="box">
        <header class="header">
            <van-nav-bar title="确认订单" left-arrow @click-left="$router.back()" />
        </header>
        <div class="content">
            <van-cell :title="checkedAddress.name + ' ' + checkedAddress.tel" :label="checkedAddress.address" is-link
                @click="$router.push('/order/list')" />
            <!-- {{ orderList }} -->
            <van-swipe-cell v-for="item in orderList" :key="item.id">
                <van-card :num="item.count" :price="item.price" :title="item.title" :thumb="item.image" />
            </van-swipe-cell>
        </div>
    </div>
    <footer class="footer">
        <van-submit-bar :price="totalPrice" button-text="在线支付" @submit="onSubmit" />
    </footer>
</template>
<script>
import { useCounterStore } from '@/store/index.js'
import { mapState, mapActions } from 'pinia'
import request from '@/utils/request.js'
export default {
    computed: {
        ...mapState(useCounterStore, ['orderList', 'totalPrice', 'checkedAddress']),
    },
    methods: {
        ...mapActions(useCounterStore, ['addmyOrder']),
        onSubmit() {
            const obj = {
                id: new Date().getTime(),// 用时间戳的毫秒值做id
                title: `No${new Date().getTime()}`,
                price: this.totalPrice / 100
            }
            this.addmyOrder({ ...obj, status: 1, orderList: this.orderList, address: this.checkedAddress })
            request.get('/pay', {
                params: obj
            }).then(res => {
                window.location.href = res.data.data
            })
        }
    }
}
</script>